"""
Case Type   : USTORE
Case Name   : 验证参数ustore_attr(ustore_verify_level)设置
Create At   : 2025/3/17
Owner       : wan005
Description :
    1.查询参数默认值
    2.修改值为ustore_verify_level=NONE;ustore_verify_module=UPAGE:UBTREE
    3.修改值为ustore_verify_level=COMPLETE;ustore_verify_module=UPAGE:UBTREE
Expect      :
    1.参数默认值ustore_verify_level=FAST;ustore_verify_module=UPAGE:UBTREE
    2.修改成功
    3.修改成功
History     :
"""
import os
import unittest
import sys
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Logger import Logger
from testcase.utils.Constant import Constant


class Security(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'---{os.path.basename(__file__)} start---')
        self.sh_primy = CommonSH('PrimaryDbUser')
        self.constant = Constant()
        self.common = Common()

    def test_ustore(self):
        text = '-----step1:查询参数默认值;expect:成功-----'
        self.logger.info(text)
        res1 = self.common.show_param('ustore_attr')
        self.assertEqual('ustore_verify_level=FAST;ustore_verify_module=UPAGE'
                         ':UBTREE', res1, text + '执行失败')

        text = '----step2:修改ustore_attr值为ustore_verify_level=NONE;' \
               'ustore_verify_module=UPAGE:UBTREE;expect:成功----'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('set', self.constant.GSGUC_SUCCESS_MSG,
                                    "ustore_attr='ustore_verify_level=NONE;"
                                    "ustore_verify_module=UPAGE:UBTREE'")
        restart_msg = self.sh_primy.restart_db_cluster()
        self.logger.info(restart_msg)
        res2 = self.common.show_param('ustore_attr')
        self.assertEqual('ustore_verify_level=NONE;'
                    'ustore_verify_module=UPAGE:UBTREE', res2, text + '执行失败')

        text = '----step3:修改ustore_attr值为ustore_verify_level=COMPLETE;' \
               'ustore_verify_module=UPAGE:UBTREE;expect:成功----'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                                    "ustore_attr='ustore_verify_level=COMPLETE;"
                                    "ustore_verify_module=UPAGE:UBTREE'")
        res3 = self.common.show_param('ustore_attr')
        self.assertEqual('ustore_verify_level=COMPLETE;ustore_verify_module='
                         'UPAGE:UBTREE', res3, text + '执行失败')

    def tearDown(self):
        text = '-----step1:清理环境，恢复配置;expect:成功-----'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                                    "ustore_attr='ustore_verify_level=FAST;"
                                    "ustore_verify_module=UPAGE:UBTREE'")
        self.sh_primy.restart_db_cluster()
        res_show = self.common.show_param('ustore_attr')
        self.assertEqual('ustore_verify_level=FAST;ustore_verify_module='
                         'UPAGE:UBTREE', res_show, text + '执行失败')
        self.logger.info(f'---{os.path.basename(__file__)} end---')
